define(function(require, exports){
	exports.onMain = function( boot, data, app ) {
		if(!app.routerValid('admin.campaign')) {
			return;
		}
		var title = LANG('推广组报表');
		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title:title,
			type: 'sidebar'
		});

		app.core.get('SYS_PLATFORM').setPlatform(title);

		con.createBusiness(data.name, 'campaign/action/list.main', {

		}, function(mod, created){
			if(created){
				mod.reload();
			}
		});

	};

	exports.onEdit = function( boot, data, app ) {
		var id = +data.param;
		var auth = id ? 'campaign.update,campaign.info' : 'campaign.add';
		var query = data.search;
		var planId;
		if(query && query.planId)
		{
			planId = +query.planId;
		}

		if(!app.routerValid(auth))
		{
			return;
		}
		var title = id ? LANG('编辑推广组') : LANG('添加推广组');

		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title: title,
			type: 'scroll'
		});

		app.core.get('SYS_PLATFORM').setPlatform(title);

		con.createBusiness(data.name, 'campaign/action/edit_old.base', {

		}, function(mod) {
			mod.reset();
			if (id)
			{
				mod.load(id);
			}
			if(planId)
			{
				mod.setPlan(planId);
				// mod.cast('setPlan',planId);
			}
		});

	};

	exports.onDiagnosis = function( boot, data, app ) {
		if(!app.routerValid('campaign.diagnosis')) {
			return;
		}
		var id = +data.param;
		var title = LANG('活动诊断');

		if (!id) {
			app.alert(LANG('缺少活动ID'));
			return app.controller.navigate('');
		}

		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title: title,
			type: 'sidebar'
		});

		con.createBusiness(data.name, 'campaign/action/diagnosis.main', {

		}, function(mod) {
			mod.reset().setTitle(title).load(id);
		});

	};

	exports.onSaveas = function( boot, data, app ) {
		if(!app.routerValid('campaign.update')) {
			return;
		}
		var id = +data.param;
		var title = LANG('活动另存为');

		if (!id) {
			app.alert(LANG('缺少活动ID'));
			return app.controller.navigate('');
		}

		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title: title,
			type: 'scroll'
		});

		var uri = 'campaign/action/edit.base';

		app.core.get('SYS_PLATFORM').setPlatform(title);

		con.createBusiness(data.name, uri, {

		}, function(mod) {
			mod.reset().setIsEdit(true).load(id, true);
		});

	};

	exports.onOneKeyDiagnosis = function( boot, data, app ) {
		if(!app.routerValid('campaign.oneKeyDiagnose'))
		{
			return;
		}

		var id = +data.param;
		var title = LANG('一键诊断');

		if (!id) {
			app.alert(LANG('缺少活动ID'));
			return app.controller.navigate('');
		}

		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title: title,
			type: 'sidebar'
		});

		con.createBusiness(data.name, 'campaign/action/diagnosis.oneKey', {
		}, function(mod) {
			mod.reset().load(id);
		});

	};
});